package org.yoyo.classroom.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.yoyo.classroom.domain.po.BookingDTO;
import org.yoyo.classroom.domain.po.BookingOrder;
import org.yoyo.classroom.mapper.BookingOrderMapper;
import org.yoyo.classroom.service.BookingRecordService;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.YearMonth;

@Service
public class BookingRecordServiceImpl implements BookingRecordService {

    @Autowired
    private BookingOrderMapper bookingOrderMapper;

    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @Override
    public int countUserMonthlyBookings(Long userId, YearMonth yearMonth) {
        return bookingOrderMapper.countUserMonthlyBookings(userId, yearMonth);
    }

    @Override
    public BookingOrder findConflictingOrders(BookingDTO bookingDTO) {
        LocalDateTime startTime = LocalDateTime.parse(bookingDTO.getStartTime(), formatter);
        LocalDateTime endTime = LocalDateTime.parse(bookingDTO.getEndTime(), formatter);
       // System.out.println(bookingOrderMapper.findConflictingOrders(bookingDTO.getSeatId(), startTime, endTime));
        return bookingOrderMapper.findConflictingOrders(bookingDTO.getSeatId(), startTime, endTime);
    }
}
